// 匹配距离, abc & a = 0.2 = [每个字符匹配到的index之和 + 目标字符串超出的长度/10]
export function matchDistance(a: string, b: string) {
  if (a.length > b.length) {
    [a, b] = [b, a];
  }
  const la = a.length;
  const lb = b.length;
  let distance = 0;
  let i = 0;
  let j = 0;
  while (i < la && j < lb) {
    if (a[i] === b[j]) {
      i += 1;
      distance += j;
      j += 1;
    }
    else {
      j += 1;
    }
  }
  if (i < la) {
    return Infinity;
  }
  return distance + (lb - j) / 10;
}